﻿//*** Guidance generated code ***//
using System;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;
using System.Web;
using System.Web.UI;

using ProjectBase.Core;

namespace ProjectBase.Mvc
{
    /// <summary>
    ///     Renders plain-text (no surrounding html is rendered). 
    ///     Should be used as an innerText of other Controls.
    /// </summary>
    public class Literal : VisualControl<ICoreModel>
    {
        // members
        string _text;
        bool _doLocalize;

        // constructor
        public Literal(string text = null, bool doLoclize = false)
        {
            SetText(text, doLoclize);
        }

        // properties
        public virtual string Text
        {
            get { return _text; }
            set { _text = value; }
        }

        public virtual bool DoLocalize
        {
            get { return _doLocalize; }
            set { _doLocalize = value; }
        }

        public override void RenderControl(HtmlTextWriter writer)
        {
            writer.Write
            (
                HttpContext.Current.Server.HtmlEncode
                (
                    DoLocalize ? GetLocalized(Text) : Text
                )
            );
        }

        // Set
        public Literal SetText(string text, bool doLoclize = false)
        {
            if (text.Is())
            {
                _text = text;
                _doLocalize = doLoclize;
            }
            return this;
        }
    }
}